const app = new Vue({
    el: "#app",
    data: {
        status: false,
        customerId: "o5GGA4gB5o5tm3Cc6z-th6IUxIWY",
        changeName: {
            districtName: "", //区域
            schoolInfo: "", //学区
            houseType: "", //房型
            ownerShip: "", //产别
            orientation: "", //朝向
            structure: "", //结构
            property: "", //物业
            renovation: "", //装修
        },
        floorChangeName: "",
        customerName: "", //客户姓名
        phoneNumber: "", //联系电话
        address: "", //地址
        area: "", //房屋面积
        districtNameShow: false, //区域
        schoolInfoShow: false, //学区
        houseTypeShow: false, //房型
        ownerShipShow: false, //产别
        orientationShow: false, //朝向
        structureShow: false, //结构
        propertyShow: false, //物业
        renovationShow: false, //装修
        floorShow: false, //楼层
        districtName: "", //区域
        schoolInfo: "", //学区
        houseType: "", //房型
        ownerShip: "", //产别
        orientation: "", //朝向
        structure: "", //结构
        property: "", //物业
        renovation: "", //装修
        floor: "", //楼层
        houseId: "", //房本编号
        districtList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ],
        schoolInfoList: [
            {
                flex: 1,
                values: [
                    "2015年至今无入学记录",
                    "2016年有入学记录",
                    "2017年有入学记录",
                    "2018年有入学记录",
                    "2019年有入学记录",
                    "2020年有入学记录",
                ],
                className: "slot1",
            },
        ], //学区选项列表
        houseTypeList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ], //房型选项列表
        ownerShipList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ], //产别选项列表
        orientationList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ], //朝向选项列表
        structureList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ], //结构选项列表
        propertyList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ], //物业类型选项列表
        renovationList: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ], //装修选项列表
        floorList: [
            {
                flex: 1,
                values: [
                    "1层",
                    "2层",
                    "3层",
                    "4层",
                    "5层",
                    "6层",
                    "7层",
                    "8层",
                    "9层",
                    "10层",
                    "11层",
                    "12层",
                    "13层",
                    "14层",
                    "15层",
                    "16层",
                    "17层",
                    "18层",
                    "19层",
                    "20层",
                    "21层",
                    "22层",
                    "23层",
                    "24层",
                    "25层",
                    "26层",
                    "27层",
                    "28层",
                    "29层",
                    "30层",
                    "31层",
                    "32层",
                    "33层",
                    "34层",
                    "35层",
                    "36层",
                    "37层",
                    "38层",
                    "39层",
                    "40层",
                    "41层",
                    "42层",
                    "43层",
                    "44层",
                    "45层",
                    "46层",
                    "47层",
                    "48层",
                    "49层",
                    "50层",
                    "51层",
                    "52层",
                    "53层",
                    "54层",
                    "55层",
                    "56层",
                    "57层",
                    "58层",
                    "59层",
                    "60层",
                ],
                className: "slot1",
            },
            {
                flex: 1,
                values: [
                    "共1层",
                    "共2层",
                    "共3层",
                    "共4层",
                    "共5层",
                    "共6层",
                    "共7层",
                    "共8层",
                    "共9层",
                    "共10层",
                    "共11层",
                    "共12层",
                    "共13层",
                    "共14层",
                    "共15层",
                    "共16层",
                    "共17层",
                    "共18层",
                    "共19层",
                    "共20层",
                    "共21层",
                    "共22层",
                    "共23层",
                    "共24层",
                    "共25层",
                    "共26层",
                    "共27层",
                    "共28层",
                    "共29层",
                    "共30层",
                    "共31层",
                    "共32层",
                    "共33层",
                    "共34层",
                    "共35层",
                    "共36层",
                    "共37层",
                    "共38层",
                    "共39层",
                    "共40层",
                    "共41层",
                    "共42层",
                    "共43层",
                    "共44层",
                    "共45层",
                    "共46层",
                    "共47层",
                    "共48层",
                    "共49层",
                    "共50层",
                    "共51层",
                    "共52层",
                    "共53层",
                    "共54层",
                    "共55层",
                    "共56层",
                    "共57层",
                    "共58层",
                    "共59层",
                    "共60层",
                ],
                className: "slot2",
            },
        ],

        houseList: [],
    },
    mounted() {
        this.getBasicData();
        this.getEvaluationHouseInfoList();
    },
    methods: {
        handleLease(id, type) {
            let data = { id };
            if (type == "lease") {
                // 出租房屋
                data.isRent = true;
            } else {
                // 取消出租
                data.isRent = false;
            }
            axios
                .post(
                    `${rht_server}HouseEvalutation/ModifyHouseEvalutationPriceIsRent`,
                    {
                        ...data,
                    }
                )
                .then((res) => {
                    if (res.data.code == 200) {
                        this.getEvaluationHouseInfoList();
                    } else {
                        console.log(err);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        handleSell(id, type) {
            let data = { id };
            if (type == "sell") {
                // 出售房屋
                data.isSell = true;
            } else {
                // 取消出售
                data.isSell = false;
            }
            axios
                .post(
                    `${rht_server}HouseEvalutation/ModifyHouseEvalutationPriceIsSell`,
                    {
                        ...data,
                    }
                )
                .then((res) => {
                    if (res.data.code == 200) {
                        this.getEvaluationHouseInfoList();
                    } else {
                        console.log(err);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        getEvaluationHouseInfoList() {
            let data = {
                customerId: this.customerId,
                pageSize: 300,
                current: 1,
            };
            axios
                .post(`${rht_server}HouseEvalutation/GetHouseEvalutationList`, {
                    ...data,
                })
                .then((res) => {
                    this.houseList = res.data.data.records;
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        addHouse() {
            // 再估一套
            this.status = !this.status;
            this.formReset();
        },
        formReset() {
            this.customerName = ""; //客户姓名
            this.phoneNumber = ""; //联系电话
            this.address = ""; //地址
            this.area = ""; //房屋面积
            this.districtNameShow = false; //区域
            this.schoolInfoShow = false; //学区
            this.houseTypeShow = false; //房型
            this.ownerShipShow = false; //产别
            this.orientationShow = false; //朝向
            this.structureShow = false; //结构
            this.propertyShow = false; //物业
            this.renovationShow = false; //装修
            this.floorShow = false; //楼层
            this.districtName = ""; //区域
            this.schoolInfo = ""; //学区
            this.houseType = ""; //房型
            this.ownerShip = ""; //产别
            this.orientation = ""; //朝向
            this.structure = ""; //结构
            this.property = ""; //物业
            this.renovation = ""; //装修
            this.floor = ""; //楼层
            this.houseId = ""; //房本编号
        },
        districtConfirm() {
            // 区域选择
            this.districtNameShow = false;
            this.districtName = this.changeName.districtName;
        },
        schoolInfoConfirm() {
            // 学区选择
            this.schoolInfoShow = false;
            this.schoolInfo = this.changeName.schoolInfo;
        },
        houseTypeConfirm() {
            // 房型选择
            this.houseTypeShow = false;
            this.houseType = this.changeName.houseType;
        },
        ownerShipConfirm() {
            // 产别选择
            this.ownerShipShow = false;
            this.ownerShip = this.changeName.ownerShip;
        },
        orientationConfirm() {
            // 朝向选择
            this.orientationShow = false;
            this.orientation = this.changeName.orientation;
        },
        structureConfirm() {
            // 结构选择
            this.structureShow = false;
            this.structure = this.changeName.structure;
        },
        propertyConfirm() {
            // 物业选择
            this.propertyShow = false;
            this.property = this.changeName.property;
        },
        renovationConfirm() {
            // 装修选择
            this.renovationShow = false;
            this.renovation = this.changeName.renovation;
        },
        floorConfirm() {
            // 楼层选择
            this.floorShow = false;
            this.floor = `${this.floorChangeName[0]}/${this.floorChangeName[1]}`;
        },
        onChangeDistrict(picker, values) {
            // 区域
            this.changeName.districtName = values[0];
        },
        onChangeSchoolInfo(picker, values) {
            // 学区
            this.changeName.schoolInfo = values[0];
        },
        onChangeHouseType(picker, values) {
            // 房型
            this.changeName.houseType = values[0];
        },
        onChangeOwnerShip(picker, values) {
            // 产别
            this.changeName.ownerShip = values[0];
        },
        onChangeOrientation(picker, values) {
            // 朝向
            this.changeName.orientation = values[0];
        },
        onChangeStructure(picker, values) {
            // 结构
            this.changeName.structure = values[0];
        },
        onChangeProperty(picker, values) {
            // 物业
            this.changeName.property = values[0];
        },
        onChangeRenovation(picker, values) {
            // 装修
            this.changeName.renovation = values[0];
        },
        onMultiChange(picker, values) {
            this.floorChangeName = values;
        },
        async getBasicData() {
            let resData = await axios.get(
                `${rht_server}BasicDataApi/GetBasicData`
            );
            resData.data.data.districtList.forEach((ele) => {
                this.districtList[0].values.push(ele.name);
            }); //区域
            resData.data.data.houseTypeList.forEach((ele) => {
                this.houseTypeList[0].values.push(ele.name);
            }); //房型
            resData.data.data.ownerShipList.forEach((ele) => {
                this.ownerShipList[0].values.push(ele.name);
            }); //产别
            resData.data.data.orientationList.forEach((ele) => {
                this.orientationList[0].values.push(ele.name);
            }); //朝向
            resData.data.data.structureList.forEach((ele) => {
                this.structureList[0].values.push(ele.name);
            }); //结构
            resData.data.data.propertyList.forEach((ele) => {
                this.propertyList[0].values.push(ele.name);
            }); //物业
            resData.data.data.renovationList.forEach((ele) => {
                this.renovationList[0].values.push(ele.name);
            }); //装修
        },
        submit() {
            if (!this.customerName) {
                this.openMessage("请输入客户姓名");
                return;
            }
            if (!this.phoneNumber) {
                this.openMessage("请输入联系电话");
                return;
            }
            if (!this.address) {
                this.openMessage("请输入详细地址");
                return;
            }
            if (this.houseId && this.houseId.length !== 17) {
                this.openMessage("房本编号必须是17位");
                return;
            }
            if (!this.districtName) {
                this.openMessage("请选择区域");
                return;
            }
            if (!this.houseType) {
                this.openMessage("请选择房型");
                return;
            }
            if (!this.ownerShip) {
                this.openMessage("请选择产别");
                return;
            }
            if (!this.orientation) {
                this.openMessage("请选择朝向");
                return;
            }
            if (!this.property) {
                this.openMessage("请选择结构");
                return;
            }
            if (!this.houseType) {
                this.openMessage("请选择物业类型");
                return;
            }
            if (!this.renovation) {
                this.openMessage("请选择装修类型");
                return;
            }
            if (!this.floor) {
                this.openMessage("请选择楼层信息");
                return;
            }
            if (!this.area) {
                this.openMessage("请输入房屋面积");
                return;
            }
            if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber)) {
                this.openMessage("手机号码有误，请重填");
                return;
            }
            let formData = {
                customerName: this.customerName, //客户姓名
                address: `${this.address}（${this.schoolInfo}）（房本编号：${this.houseId}）`, //地址
                district: this.districtName, //区域
                houseLayout: this.houseType, //房型
                ownerShip: this.ownerShip, //产别
                houseOrientation: this.orientation, //朝向
                structure: this.structure, //结构
                propertyManagementCompanyType: this.property, //物业
                decorationType: this.renovation, //装修
                floor: this.floor, //楼层
                area: this.area, //面积
                phoneNumber: this.phoneNumber, //电话
                customerId: this.customerId, //客户customerId
            };
            axios
                .post(
                    `${rht_server}HouseEvalutation/SubmitHouseEvalutaionInfo`,
                    {
                        ...formData,
                    }
                )
                .then((res) => {
                    this.status = false;
                    this.$messagebox({
                        $type: "prompt",
                        title: "提示",
                        message:
                            "您的评估信息已收到，我们将人工对您的房屋进行评估，结果将在三到七个工作日内给您回复，您也可以到就近的连锁店进行咨询。",
                        inputPlaceholder: "请输入秘钥",
                        showCancelButton: true,
                        cancelButtonText: "取消",
                        confirmButtonText: "去咨询",
                        inputType: "password",
                    })
                        .then(({ value, action }) => {
                            console.log("用户点击了去咨询");
                        })
                        .catch(() => {
                            console.log("用户点击了取消");
                        });
                });
        },
        openMessage(message) {
            this.$toast({
                message: message,
                duration: 3000,
            });
        },
    },
});
